from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-09 14:08:58.607575
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 09, Sep, 2022
Time: 14:09:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3704
Nobs: 774.000 HQIC: -50.7032
Log likelihood: 9908.35 FPE: 7.75374e-23
AIC: -50.9113 Det(Omega_mle): 6.90773e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298609 0.054323 5.497 0.000
L1.Burgenland 0.107101 0.036167 2.961 0.003
L1.Kärnten -0.106767 0.019223 -5.554 0.000
L1.Niederösterreich 0.205095 0.075706 2.709 0.007
L1.Oberösterreich 0.114742 0.073263 1.566 0.117
L1.Salzburg 0.253231 0.038711 6.542 0.000
L1.Steiermark 0.036174 0.050464 0.717 0.473
L1.Tirol 0.106710 0.040890 2.610 0.009
L1.Vorarlberg -0.060610 0.035174 -1.723 0.085
L1.Wien 0.050356 0.065106 0.773 0.439
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058645 0.112786 0.520 0.603
L1.Burgenland -0.033570 0.075090 -0.447 0.655
L1.Kärnten 0.047589 0.039911 1.192 0.233
L1.Niederösterreich -0.176409 0.157183 -1.122 0.262
L1.Oberösterreich 0.395633 0.152110 2.601 0.009
L1.Salzburg 0.289553 0.080373 3.603 0.000
L1.Steiermark 0.106290 0.104775 1.014 0.310
L1.Tirol 0.313824 0.084896 3.697 0.000
L1.Vorarlberg 0.027290 0.073029 0.374 0.709
L1.Wien -0.021769 0.135175 -0.161 0.872
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191662 0.027899 6.870 0.000
L1.Burgenland 0.089549 0.018574 4.821 0.000
L1.Kärnten -0.008488 0.009872 -0.860 0.390
L1.Niederösterreich 0.260676 0.038881 6.704 0.000
L1.Oberösterreich 0.134133 0.037626 3.565 0.000
L1.Salzburg 0.046017 0.019881 2.315 0.021
L1.Steiermark 0.018069 0.025917 0.697 0.486
L1.Tirol 0.093049 0.021000 4.431 0.000
L1.Vorarlberg 0.058368 0.018065 3.231 0.001
L1.Wien 0.118060 0.033437 3.531 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108625 0.028399 3.825 0.000
L1.Burgenland 0.046968 0.018907 2.484 0.013
L1.Kärnten -0.015056 0.010049 -1.498 0.134
L1.Niederösterreich 0.191263 0.039578 4.833 0.000
L1.Oberösterreich 0.290208 0.038300 7.577 0.000
L1.Salzburg 0.112066 0.020237 5.538 0.000
L1.Steiermark 0.102364 0.026382 3.880 0.000
L1.Tirol 0.111103 0.021376 5.197 0.000
L1.Vorarlberg 0.069675 0.018388 3.789 0.000
L1.Wien -0.017895 0.034036 -0.526 0.599
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130972 0.051542 2.541 0.011
L1.Burgenland -0.050924 0.034315 -1.484 0.138
L1.Kärnten -0.040180 0.018239 -2.203 0.028
L1.Niederösterreich 0.170826 0.071830 2.378 0.017
L1.Oberösterreich 0.138446 0.069512 1.992 0.046
L1.Salzburg 0.287417 0.036730 7.825 0.000
L1.Steiermark 0.034431 0.047881 0.719 0.472
L1.Tirol 0.161587 0.038796 4.165 0.000
L1.Vorarlberg 0.100699 0.033373 3.017 0.003
L1.Wien 0.068604 0.061773 1.111 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056366 0.041028 1.374 0.169
L1.Burgenland 0.040404 0.027316 1.479 0.139
L1.Kärnten 0.050667 0.014518 3.490 0.000
L1.Niederösterreich 0.220770 0.057179 3.861 0.000
L1.Oberösterreich 0.283280 0.055333 5.120 0.000
L1.Salzburg 0.045605 0.029237 1.560 0.119
L1.Steiermark -0.001128 0.038114 -0.030 0.976
L1.Tirol 0.147577 0.030883 4.779 0.000
L1.Vorarlberg 0.073051 0.026566 2.750 0.006
L1.Wien 0.084191 0.049172 1.712 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180364 0.049125 3.672 0.000
L1.Burgenland -0.006338 0.032706 -0.194 0.846
L1.Kärnten -0.061194 0.017384 -3.520 0.000
L1.Niederösterreich -0.083223 0.068462 -1.216 0.224
L1.Oberösterreich 0.195349 0.066253 2.949 0.003
L1.Salzburg 0.056513 0.035007 1.614 0.106
L1.Steiermark 0.231746 0.045636 5.078 0.000
L1.Tirol 0.493566 0.036977 13.348 0.000
L1.Vorarlberg 0.048057 0.031808 1.511 0.131
L1.Wien -0.052676 0.058876 -0.895 0.371
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166401 0.056380 2.951 0.003
L1.Burgenland -0.010361 0.037536 -0.276 0.783
L1.Kärnten 0.067069 0.019951 3.362 0.001
L1.Niederösterreich 0.206106 0.078573 2.623 0.009
L1.Oberösterreich -0.070904 0.076037 -0.932 0.351
L1.Salzburg 0.211685 0.040177 5.269 0.000
L1.Steiermark 0.115459 0.052375 2.204 0.027
L1.Tirol 0.072112 0.042438 1.699 0.089
L1.Vorarlberg 0.121615 0.036506 3.331 0.001
L1.Wien 0.122421 0.067571 1.812 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357806 0.032612 10.972 0.000
L1.Burgenland 0.005239 0.021712 0.241 0.809
L1.Kärnten -0.023357 0.011540 -2.024 0.043
L1.Niederösterreich 0.214775 0.045449 4.726 0.000
L1.Oberösterreich 0.188087 0.043982 4.276 0.000
L1.Salzburg 0.046362 0.023240 1.995 0.046
L1.Steiermark -0.015752 0.030295 -0.520 0.603
L1.Tirol 0.106622 0.024547 4.344 0.000
L1.Vorarlberg 0.073552 0.021116 3.483 0.000
L1.Wien 0.048052 0.039085 1.229 0.219
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040237 0.148557 0.192374 0.156905 0.124571 0.112932 0.066041 0.222272
Kärnten 0.040237 1.000000 -0.003956 0.132065 0.041637 0.095695 0.430481 -0.052343 0.100197
Niederösterreich 0.148557 -0.003956 1.000000 0.337429 0.151566 0.298540 0.108085 0.183462 0.323634
Oberösterreich 0.192374 0.132065 0.337429 1.000000 0.227982 0.330237 0.172287 0.168085 0.265198
Salzburg 0.156905 0.041637 0.151566 0.227982 1.000000 0.147401 0.122860 0.147257 0.133428
Steiermark 0.124571 0.095695 0.298540 0.330237 0.147401 1.000000 0.151581 0.138652 0.079606
Tirol 0.112932 0.430481 0.108085 0.172287 0.122860 0.151581 1.000000 0.114987 0.153422
Vorarlberg 0.066041 -0.052343 0.183462 0.168085 0.147257 0.138652 0.114987 1.000000 0.006780
Wien 0.222272 0.100197 0.323634 0.265198 0.133428 0.079606 0.153422 0.006780 1.000000